<template>
  <div>
    <el-header>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{name: 'publicInfo' }">公共信息</el-breadcrumb-item>
        <el-breadcrumb-item>{{this.title}}</el-breadcrumb-item>
      </el-breadcrumb>
    </el-header>
    <el-main>
      <CommonTable
        :data="detailData"
        :option="option"
        :page="page"
        @changePage="changePage"
        @search="search">
      </CommonTable>
    </el-main>
  </div>
</template>

<script>
  import CommonTable from '@/components/common/CommonTable'
  import {queryLoss} from '@/api/bankBiz/loss/loss'

  export default {
    name: 'tableView',
    components: {
      CommonTable
    },
    self: this,
    data () {
      return {
        namespace: '',
        nameFlag: '',
        title: '',
        page: {
          "pageSizes": [
            10,
            20,
            30,
            40,
            50,
            100
          ],
          "currentPage": 1,
          "total": "",
          "pageSize": 10
        },
        detailData: [],
        option: {},
        query: {
          sort: {},
          where: {},
          namespace: "PublicInfo",
          key:"",
          pageSize: 10,
          currentPage: 1
        },
        flag: 0,
        optionPublic: {
          "searchMenuSpan": 8,
          "align": "center",
          "column": [
            {
              "label": "序号",
              "prop": "serialNumber"
            },
            {
              "label": "币种",
              "prop": "currency",
              "search": true,
              "type": "select",
              "dicData": [
                {
                  "label": "不限",
                  "value": "0"
                },
                {
                  "label": "人民币元",
                  "value": "1"
                },
                {
                  "label": "美元",
                  "value": "2"
                },
                {
                  "label": "英镑",
                  "value": "3"
                },
                {
                  "label": "港币",
                  "value": "4"
                },
                {
                  "label": "加拿大元",
                  "value": "5"
                },
                {
                  "label": "澳元",
                  "value": "6"
                },
                {
                  "label": "欧元",
                  "value": "7"
                },
                {
                  "label": "日元",
                  "value": "8"
                },
                {
                  "label": "瑞士法郎",
                  "value": "9"
                },
                {
                  "label": "新加坡元",
                  "value": "10"
                }
              ]
            },
            {
              "label": "利率名称",
              "prop": "interestRateName"
            },
            {
              "label": "存款方式",
              "prop": "depositMethod",
              "search": true,
              "type": "select",
              "dicData": [
                {
                  "label": "不限",
                  "value": "0"
                },
                {
                  "label": "活期存款",
                  "value": "1"
                },
                {
                  "label": "整存整取",
                  "value": "2"
                },
                {
                  "label": "零存整取",
                  "value": "3"
                },
                {
                  "label": "整存零取",
                  "value": "4"
                },
                {
                  "label": "定活两便",
                  "value": "5"
                },
                {
                  "label": "存本取息",
                  "value": "6"
                },
                {
                  "label": "通知存款",
                  "value": "7"
                }
              ]
            },
            {
              "label": "利率",
              "prop": "interestRate"
            },
            {
              "label": "利率类型",
              "prop": "interestRateType"
            },
            {
              "label": "有效期限",
              "prop": "validityPeriod"
            }
          ],
          "searchBtn": false,
          "refreshBtn": false,
          "menu": false,
          "menuAlign": "center",
          "menuPosition": "right",
          "columnBtn": false,
          "addBtn": false
        },
        optionPublic1: {
          "searchMenuSpan": 8,
          "align": "center",
          "menuAlign": "center",
          "searchBtn": false,
          "menuPosition": "right",
          "column": [
            {
              "label": "序号",
              "prop": "serialNumber"
            },
            {
              "label": "汇率日期",
              "prop": "exchangeRateDate",
              "search": true,
              "type": "date"
            },
            {
              "label": "币种",
              "prop": "currency"
            },
            {
              "label": "汇买价",
              "prop": "exchangePurchasePrice"
            },
            {
              "label": "钞买价",
              "prop": "purchasePrice"
            },
            {
              "label": "卖出价",
              "prop": "sellingPrice"
            },
            {
              "label": "基准价",
              "prop": "benchmarkPrice"
            }
          ],
          "refreshBtn": false,
          "menu": false,
          "columnBtn": false,
          "addBtn": false
        },
        optionPublic2: {
          "searchMenuSpan": 4,
          "align": "center",
          "menuAlign": "center",
          "searchBtn": false,
          "menuPosition": "right",
          "column": [
            {
              "label": "序号",
              "prop": "serialNumber"
            },
            {
              "label": "产品名称",
              "prop": "productName"
            },
            {
              "label": "产品类型",
              "prop": "productType",
              "search": true,
              "searchSpan": 4,
              "type": "select",
              "dicData": [
                {
                  "label": "不限",
                  "value": "0"
                },
                {
                  "label": "固定收益类",
                  "value": "1"
                },
                {
                  "label": "现金管理类",
                  "value": "2"
                },
                {
                  "label": "净值型类基金",
                  "value": "3"
                }
              ]
            },
            {
              "label": "收益类型",
              "prop": "incomeType",
              "search": true,
              "searchSpan": 4,
              "type": "select",
              "dicData": [
                {
                  "label": "不限",
                  "value": "0"
                },
                {
                  "label": "保本保收益",
                  "value": "1"
                },
                {
                  "label": "保本浮动收益",
                  "value": "2"
                },
                {
                  "label": "不保本浮动收益",
                  "value": "3"
                }
              ]
            },
            {
              "label": "风险等级",
              "prop": "riskLevel",
              "search": true,
              "searchSpan": 4,
              "type": "select",
              "dicData": [
                {
                  "label": "不限",
                  "value": "0"
                },
                {
                  "label": "R1低风险",
                  "value": "1"
                },
                {
                  "label": "R2中低风险",
                  "value": "2"
                },
                {
                  "label": "R3中等风险",
                  "value": "3"
                },
                {
                  "label": "R4中高风险",
                  "value": "4"
                },
                {
                  "label": "R5高风险",
                  "value": "5"
                }
              ]
            },
            {
              "label": "起购金额",
              "prop": "purchaseAmount",
              "search": true,
              "searchSpan": 4,
              "type": "select",
              "dicData": [
                {
                  "label": "不限",
                  "value": "0"
                },
                {
                  "label": "0-1万",
                  "value": "1"
                },
                {
                  "label": "1-5万",
                  "value": "2"
                },
                {
                  "label": "5-10万",
                  "value": "3"
                },
                {
                  "label": "10万以上",
                  "value": "4"
                }
              ]
            },
            {
              "label": "产品期限",
              "prop": "productTerm",
              "search": true,
              "searchSpan": 4,
              "type": "select",
              "dicData": [
                {
                  "label": "不限",
                  "value": "0"
                },
                {
                  "label": "30天以下（含）",
                  "value": "1"
                },
                {
                  "label": "1-3月（含）",
                  "value": "2"
                },
                {
                  "label": "3-6月（含）",
                  "value": "3"
                },
                {
                  "label": "6-12月（含）",
                  "value": "4"
                },
                {
                  "label": "一年以上",
                  "value": "5"
                },
                {
                  "label": "无固定期限",
                  "value": "6"
                }
              ]
            },
            {
              "label": "业绩基准/七日年化收益率",
              "prop": "performanceBenchmark",
              "search": false
            }
          ],
          "refreshBtn": false,
          "menu": false,
          "columnBtn": false,
          "addBtn": false
        },
        optionPublic3: {
          "searchMenuSpan": 8,
          "align": "center",
          "menuAlign": "center",
          "searchBtn": false,
          "menuPosition": "right",
          "column": [
            {
              "label": "序号",
              "prop": "serialNumber"
            },
            {
              "label": "贷款方式",
              "prop": "loanMethod",
              "search": true,
              "searchSpan": 4,
              "type": "select",
              "dicData": [
                {
                  "label": "不限",
                  "value": "0"
                },
                {
                  "label": "个人消费贷款",
                  "value": "1"
                },
                {
                  "label": "个人经营贷款",
                  "value": "2"
                },
                {
                  "label": "个人购房贷款",
                  "value": "3"
                },
                {
                  "label": "个人质押贷款",
                  "value": "4"
                },
                {
                  "label": "企业固定资产贷款",
                  "value": "5"
                },
                {
                  "label": "企业流动资金贷款",
                  "value": "6"
                },
                {
                  "label": "经营性物业贷款",
                  "value": "7"
                }
              ]
            },
            {
              "label": "利率名称",
              "prop": "interestRateName"
            },
            {
              "label": "利率",
              "prop": "interestRate"
            },
            {
              "label": "贷款期限",
              "prop": "loanTerm",
              "search": true,
              "searchSpan": 4,
              "type": "select",
              "dicData": [
                {
                  "label": "不限",
                  "value": "0"
                },
                {
                  "label": "一年以内（含）",
                  "value": "1"
                },
                {
                  "label": "1-5年（含）",
                  "value": "2"
                },
                {
                  "label": "5年以上",
                  "value": "3"
                }
              ]
            },
            {
              "label": "万元到期利息",
              "prop": "tenThousandInterestDue"
            },
            {
              "label": "利率类型",
              "prop": "interestRateType"
            }
          ],
          "refreshBtn": false,
          "menu": false,
          "columnBtn": false,
          "addBtn": false
        }
      }
    },
    mounted () {
      // this.currencyTable()
    },
    methods: {
      // 初始化配置
      initOptions () {
        this.nameFlag = this.$route.path.split('/')[2]
        if ('depositInterestRateInquiry' == this.nameFlag) {
          this.flag = 0
        } else if ('exchangeRateInquiry' == this.nameFlag) {
          this.flag = 1
        } else if ('financialInterestRateInquiry' == this.nameFlag) {
          this.flag = 2
        } else if ('loanInterestRateInquiry' == this.nameFlag) {
          this.flag = 3
        }
        this.currencyTable(this.flag)
      },
      // 切换分页
      changePage(pageInfo) {
        this.$message.success('分页信息:' + JSON.stringify(pageInfo))
        this.query.currentPage = pageInfo.currentPage
        this.query.pageSize = pageInfo.pageSize
        if (this.flag === 0) {
          this.query.key = "depositInterestRateInquiry"
        } else if (this.flag === 1) {
          this.query.key = "exchangeRateInquiry"
        } else if (this.flag === 2) {
          this.query.key = "financialInterestRateInquiry"
        } else if (this.flag === 3) {
          this.query.key = "loanInterestRateInquiry"
        }
        // 调接口
        queryLoss(this.query).then((res) => {
          if(res.data.code == 200){
            if (this.flag === 0) {
              this.title = '存款利率查询'
              this.page.total = res.data.data.totalNum
              this.detailData = res.data.data.dataObj
              this.option = this.optionPublic
            } else if (this.flag === 1) {
              this.title = '汇率查询'
              this.page.total = res.data.data.totalNum
              this.detailData = res.data.data.dataObj
              this.option = this.optionPublic1
            } else if (this.flag === 2) {
              this.title = '理财利率查询'
              this.page.total = res.data.data.totalNum
              this.detailData = res.data.data.dataObj
              this.option = this.optionPublic2
            } else if (this.flag === 3) {
              this.title = '贷款利率查询'
              this.page.total = res.data.data.totalNum
              this.detailData = res.data.data.dataObj
              this.option = this.optionPublic3
            }
          }else{
            this.title = ''
            this.page.total = 0
            this.detailData = []
            this.option = {}
            window.globalUiKit.notify('提示', res.data.message, 'error')
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      // 搜索
      search(params) {
        this.where = params
        // 调接口

      },
      currencyTable (i) {
        if (i === 0) {
          this.query.key = "depositInterestRateInquiry"
        } else if (i === 1) {
          this.query.key = "exchangeRateInquiry"
        } else if (i === 2) {
          this.query.key = "financialInterestRateInquiry"
        } else if (i === 3) {
          this.query.key = "loanInterestRateInquiry"
        }
        // 调接口
        queryLoss(this.query).then((res) => {
          if(res.data.code == 200){
            if (i === 0) {
              this.title = '存款利率查询'
              this.page.total = res.data.data.totalNum
              this.detailData = res.data.data.dataObj
              this.option = this.optionPublic
            } else if (i === 1) {
              this.title = '汇率查询'
              this.page.total = res.data.data.totalNum
              this.detailData = res.data.data.dataObj
              this.option = this.optionPublic1
            } else if (i === 2) {
              this.title = '理财利率查询'
              this.page.total = res.data.data.totalNum
              this.detailData = res.data.data.dataObj
              this.option = this.optionPublic2
            } else if (i === 3) {
              this.title = '贷款利率查询'
              this.page.total = res.data.data.totalNum
              this.detailData = res.data.data.dataObj
              this.option = this.optionPublic3
            }
          }else{
            this.title = ''
            this.page.total = 0
            this.detailData = []
            this.option = {}
            window.globalUiKit.notify('提示', res.data.message, 'error')
          }
        }).catch((err) => {
          console.log(err)
        })
      }
    },
    beforeRouteEnter (to, from, next) {
      next((vm) => {
        vm.initOptions()
      })
    }
  }
</script>

<style>
</style>
